<?php
$username = 'root';
$password = 'root';

$pdo = new PDO('mysql:host=localhost;dbname=test;charset=utf8',$username,$password);

$user = $_POST['username'];
$pass = md5($_POST['password']);

$sql = "select * from users where username='{$user}' and password='{$pass}'";

$row = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);

if($row){
  echo json_encode([
    'code'=>0,
    'type'=>'success',
    'msg'=>'用户已存在',
    'data'=>[
      'username'=>$user,
      'openid'=>$row['id']
    ]
  ]);
}else{
  echo json_encode([
    'code'=>1000,
    'msg'=>'注册成功',
    'data'=>[]
  ]);
}